package com.rock.code.system.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.common.pager.Page;
import com.rock.code.system.user.dao.TbSysLoginmsgDao;
import com.rock.code.system.user.domain.TbSysLoginmsg;
import com.rock.code.system.user.service.TbSysLoginmsgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 用户管理 Service 实现
 *
 * @author kongqiang
 * @date 2017 /04/06
 */
@Service
public class TbSysLoginmsgServiceImpl extends BaseServiceImpl<TbSysLoginmsgDao> implements TbSysLoginmsgService {

    @Resource
    private TbSysLoginmsgDao tbSysLoginmsgDao;

    /**
     * Insert.
     *
     * @param tbSysLoginmsg the TbSysLoginmsg
     * @return the int
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public int insert(TbSysLoginmsg tbSysLoginmsg) throws Exception {
//        tbSysLoginmsg.setloginId(RandomGUID.getRandomGUID());
        tbSysLoginmsg.setLoginId( tbSysLoginmsg.getLoginCode());
        return tbSysLoginmsgDao.insert(tbSysLoginmsg);
    }

    /**
     * Delete.
     *
     * @param primaryKey the primary key
     * @return the int
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public int delete(String primaryKey) throws Exception {
        return tbSysLoginmsgDao.delete(primaryKey);
    }

    /**
     * Delete by param.
     *
     * @param param the param
     * @return the int
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public int deleteByParam(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.deleteByParam(param);
    }

    /**
     * Update.f
     *
     * @param tbSysLoginmsg the TbSysLoginmsg
     * @return the int
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public int update(TbSysLoginmsg tbSysLoginmsg) throws Exception {
        return tbSysLoginmsgDao.update(tbSysLoginmsg);
    }

    /**
     * Query tb sys loginmsg.
     *
     * @param tbSysLoginmsg the tb sys loginmsg
     * @return the tb sys loginmsg
     * @throws Exception the exception
     * @author kongqiang
     * @date 2018 /06/15
     */
    @Override
    public TbSysLoginmsg query(TbSysLoginmsg tbSysLoginmsg) throws Exception {
        return tbSysLoginmsgDao.query(tbSysLoginmsg);
    }

    /**
     * Query by para map.
     *
     * @param param the param
     * @return the tbSysLoginmsg
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public TbSysLoginmsg queryByParaMap(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.queryByParaMap(param);
    }

    /**
     * Query list.
     *
     * @param tbSysLoginmsg the TbSysLoginmsg
     * @return the list
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public List<TbSysLoginmsg> queryList(TbSysLoginmsg tbSysLoginmsg) throws Exception {
        return tbSysLoginmsgDao.queryList(tbSysLoginmsg);
    }

    /**
     * Query list by para map.
     *
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public List<TbSysLoginmsg> queryListByParaMap(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.queryListByParaMap(param);
    }

    /**
     * Query page list.
     *
     * @param page  the page
     * @param param the param
     * @return the page info
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017 /04/06
     */
    @Override
    public PageInfo queryPageList(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        PageHelper.startPage(page.getPage(), page.getRows());
        if (!orderBy.equals("")) {
            PageHelper.orderBy(orderBy);
        }
        List<TbSysLoginmsg> list = tbSysLoginmsgDao.queryListByParaMap(param);
        return new PageInfo(list);
    }

    /**
     * Query list by order.
     *
     * @param page  the page
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author kongqiang
     * @date 2018.01.02 /06/15
     */
    public List<TbSysLoginmsg> queryListByOrder(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        if (!orderBy.equals("")) {
            param.put("orderBy", orderBy);
        }
        return tbSysLoginmsgDao.queryListByParaMap(param);
    }

    /**
     * Login by para map.
     *
     * @param param the param
     * @return the tb sys user
     * @throws Exception the exception
     * @author kongqiang
     * @date 2017.04.06 /06/15
     */
    @Override
    public TbSysLoginmsg loginByParaMap(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.loginByParaMap(param);
    }

    /**
     * Login by para map.
     *
     * @param param the param
     * @return the tb sys user
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018.01.23 /06/15
     */
    @Override
    public int updatePassword(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.updatePassword(param);
    }

    /**
     * Query cas realm tb sys loginmsg.
     *
     * @param param the param
     * @return the tb sys loginmsg
     * @throws Exception the exception
     * @author kongqiang
     * @date 2018 /06/15
     */
    @Override
    public TbSysLoginmsg queryCasRealm(Map<String, Object> param) throws Exception {
        return tbSysLoginmsgDao.queryCasRealm(param);
    }

}